<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>详情页</h1>
    <div class="box">
        
    </div>
    <script>

        var val = location.href;
        // console.log(val);
        var reg = /id=([a-z0-9]+)&/g;
        var res = reg.test(val);
        // console.log(res);
        var id = RegExp.$1;
        console.log(id);

         var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                var data = JSON.parse(xhr.responseText).data;
                console.log(data);
                var str = `<h1>${data.title}</h1>${data.content}`;
                document.querySelector(".box").innerHTML = str;
            }
        }
        xhr.open("get",`https://cnodejs.org/api/v1/topic/${id}`);
        xhr.send();



        
        // console.log(location.search);  
        // var urlstr = location.search.substr(1);
        // // console.log(urlstr); //id=62e0d536d3061f33b8e85386&name=lili
        // var arr = urlstr.split("&");
        // // console.log(arr); // [ id=62e0d536d3061f33b8e85386,name=lili ]
        // var obj = {};
        // for(var i = 0;i < arr.length;i++){
        //     var arr1 = arr[i].split("="); 
        //     console.log(arr1); //[id,""]    [name,""]
        //     obj[arr1[0]] = arr1[1]; // obj["id"] = "62e0d536d3061f33b8e85386"  ;  obj["name"] = "lili"
        // }
        // console.log(obj);
    </script>
</body>
</html>